package com.ruoyi.patrol.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.patrol.domain.PtWorkOrderType;
import com.ruoyi.patrol.service.IPtWorkOrderTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工单类型管理
 * @author zyh
 */
@RestController
@RequestMapping("/work/orderType")
public class PtWorkOrderTypeController extends BaseController {

    @Autowired
    private IPtWorkOrderTypeService workOrderTypeService;

    /**
     * 新增工单类型
     * @param workOrderType
     * @return
     */
    @PostMapping
    public AjaxResult save(@RequestBody PtWorkOrderType workOrderType) {

        int row = workOrderTypeService.save(workOrderType);
        return toAjax(row);
    }

    /**
     * 分页查询工单类型
     * @param workOrderType
     * @return
     */
    @GetMapping("/page")
    public TableDataInfo page(PtWorkOrderType workOrderType) {
        startPage();
        List<PtWorkOrderType> list = workOrderTypeService.selectWorkOrderTypeList(workOrderType);
        return getDataTable(list);
    }

    /**
     * 获取工单类型详情
     * @param id
     * @return
     */
    @GetMapping("/info/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        PtWorkOrderType workOrderType = workOrderTypeService.selectWorkOrderTypeById(id);
        return AjaxResult.success(workOrderType);
    }

    /**
     * 更新工单类型
     * @param workOrderType
     * @return
     */
    @PutMapping
    public AjaxResult edit(@RequestBody PtWorkOrderType workOrderType) {
        int row = workOrderTypeService.update(workOrderType);
        return toAjax(row);
    }

    @DeleteMapping("{ids}")
    public AjaxResult delete(@PathVariable("ids") Long[] ids) {
        return toAjax(workOrderTypeService.delete(ids));
    }
}
